package o2o.web.actions.user;

import com.jinyou.utils.common.*;
import com.jinyou.utils.security.EncrypMD5;
import com.jinyou.web.filters.RightFilter;
import com.jinyouapp.common.tools.jms.model.JMSNotify;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import o2o.business.device.AppDeviceInfoBusiness;
import o2o.business.sms.JYSmsSeverBusiness;
import o2o.business.sms.SmsBusiness;
import o2o.business.sms.SmsUserInfoException;
import o2o.business.sms.UserSMSInfoParams;
import o2o.business.sms.data.SMS_TYPE;
import o2o.cache.agent.CityAgentMemory;
import o2o.cache.company.postman.PostCompanyMemory;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.shop.ShopExtraInfoMemory;
import o2o.cache.shop.ShopMemory;


import o2o.cache.sys.SysCustomerCache;
import o2o.cache.user.*;
import o2o.config.dao.MongoDaoImpl;
import o2o.config.dao.UserDaoSql;
import o2o.config.dao.utils.DaoUtils;
import o2o.config.dao.utils.Expression;
import o2o.config.dao.utils.QueryCondition;
import o2o.config.jms.config.JMSTypeContent;
import o2o.config.jms.sender.JmsSender;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.agent.CityAgent;
import o2o.dao.PO.common.ResultInfo;
import o2o.dao.PO.common.UserType;
import o2o.dao.PO.company.postman.PostCompanyInfo;
import o2o.postman.model.CityPostman;
import o2o.dao.PO.postman.POSTMAN_TYPE;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.shop.ShopInfoExtra;
import o2o.dao.PO.sys.SysCityAdmin;
import o2o.dao.PO.sys.SysCustomerInfo;
import o2o.dao.PO.sys.SysSetting;
import o2o.dao.PO.user.*;
import o2o.dao.PO.wallet.UserWallet;
import o2o.dao.VO.agent.CityAgentVO;
import o2o.dao.VO.authrole.UserRoleAuthInfoVO;
import o2o.dao.VO.common.FileUploadInfo;
import o2o.dao.VO.company.postman.PostCompanyInfoVO;
import o2o.dao.VO.postman.CityPostmanVO;
import o2o.dao.VO.shop.ShopInfoVO;
import o2o.dao.VO.shop.ShopTypeInfoVO;
import o2o.dao.VO.user.*;
import o2o.system.Common;
import o2o.system.data.PROMPTS;
import o2o.system.data.SYS_CONFIG_PATH;
import o2o.system.data.SYS_SETTINGS;
import o2o.task.user.UserDistributeInfoSyncUtils;
import o2o.utils.MultilingualResult;
import o2o.web.actions.authrole.AuthRoleMan;
import o2o.web.actions.company.SysCityCompanyMan;
import o2o.web.actions.postman.PostmanMan;
import o2o.web.actions.shop.ShopCategoryMan;

import o2o.web.actions.wallet.WalletAction;
import org.apache.commons.lang.StringUtils;
import org.apache.http.util.TextUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import static o2o.web.actions.user.UserLogin.*;

@Controller
@Api(tags = "用户管理")
public class UserAction {

    // 限制短信发送频率  <ip,访问时间>
    private ConcurrentHashMap<String, Long> requestMap = new ConcurrentHashMap<>();

    // 用户修改登录账号 step 1 获取验证码 2
    @RequestMapping("/user/login/phone/modify")
    @ResponseBody
    public String user_modify_login_phone(HttpServletRequest request, String sysAppKey, String token,
                                          String areaCode,// 手机区号
                                          String oldPhone, String nowPhone, String telCode, Integer step, String lang) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (step == null) {
            return AjaxResult.errorResult("请选择操作类型");
        }
        switch (step) {
            case 1:
            case 3: {
                if (step == 1 ? StringUtils.isEmpty(oldPhone) : StringUtils.isEmpty(nowPhone)) {
                    return AjaxResult.errorResult("请输入电话号");
                }
                if (step == 1) {
                    if (StringUtils.isEmpty(user.getPhone()) || !user.getPhone().equals(oldPhone)) {
                        return AjaxResult.errorResult("输入的手机号与登陆账号不一致");
                    }
                } else {
                    // 检测当前账号是否已经注册了
                    QueryCondition query = QueryCondition.getInstance();
                    query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("phone", nowPhone));
                    int count;
                    try {
                        count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
                    } catch (SQLException e) {
                        e.printStackTrace();
                        return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
                    }
                    if (count > 0) {
                        return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
                    }
                }
                boolean canSend = true;
                int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;
                //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
                if (userRegisterNeedCode == 1) {
                    try {
                        canSend = SmsBusiness.getInstance().canSend(step == 3 ? nowPhone : oldPhone);
                    } catch (SmsUserInfoException e) {
                        System.out.println(step == 3 ? nowPhone : oldPhone + "," + e.getMessage());
                        return AjaxResult.errorResult(e.getMessage());
                    }
                }
                //验证未通过
                if (!canSend) {
                    return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
                }
                // 将注册用户的验证码存储在mongoDB
                String code = ToolUtils.getTelCode(); // 6位随机码
                BasicDBObject document = new BasicDBObject();
                document.put("username", step == 1 ? oldPhone : nowPhone);

                DBObject value1 = new BasicDBObject();
                value1.put("telCode", code);
                value1.put("createTim", SysSetting.getCurDate());
                DBObject upValue = new BasicDBObject();
                upValue.put("$push", value1); // 数组的形式

                boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB,
                        UserSMSInfoParams.MonUserSMSRegCol, document, upValue, true);
                if (flag == true) {
                    if (userRegisterNeedCode == 1) {
                        JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, step == 1 ? oldPhone : nowPhone, SMS_TYPE.REGISTER, code, RightFilter.getIpAddr(request));
                    }
                    StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
                    System.out.println("{\"status\":1,\"telCode\":\"" + code + "\"}\"");
                    return buffer.toString();
                } else {
                    return MultilingualResult.errorResultV2(PROMPTS.GET_CODE_FAILED, lang);
                }
            }
            case 2:
            case 4: {
                if (step == 2 ? StringUtils.isEmpty(oldPhone) : StringUtils.isEmpty(nowPhone)) {
                    return AjaxResult.errorResult("请输入电话号");
                }
                if (StringUtils.isEmpty(telCode)) {
                    return AjaxResult.errorResult("验证码不能为空");
                }
                // 判断验证码是否正确
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("username", step == 2 ? oldPhone : nowPhone);
                List<HashMap<String, Object>> list = MongoDaoImpl.getInstance().find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSRegCol, map, 1);
                if (list == null || list.size() < 1) {
                    return AjaxResult.errorResult("请获取验证码");
                }
                // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
                if (list.get(0).get("telCode") == null
                        || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
                    return AjaxResult.errorResult("请输入正确的验证码！");
                }
                // 步骤二
                // 步骤四的话需要修改登录的电话账号
                if (step == 4) {
                    // 检测当前账号是否已经注册了
                    QueryCondition query = QueryCondition.getInstance();
                    query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("phone", nowPhone));
                    int count;
                    try {
                        count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
                    } catch (SQLException e) {
                        e.printStackTrace();
                        return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
                    }
                    if (count > 0) {
                        return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
                    }
                    StringBuilder sql = new StringBuilder();
                    sql.append("update ").append(PojoTables.UserInfo).append(" set ")
                            .append("updateUser ='").append(user.getUsername()).append("'")
                            .append(",phone = ").append("'").append(nowPhone).append("'").append(" where ")
                            .append(" username =").append("'").append(user.getUsername()).append("'").append(" and delFlag = 0");
                    try {
                        UserDaoSql.getInstance().executeBySql(sql.toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                        return AjaxResult.errorResult("操作失败,请稍后重试");
                    }
                    //
                    UserInfoMemory.getInstance().modifyUserInfo(user.getUsername());
                    try {
                        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_INFO_MODIFY).setStr01(user.getUsername());//o2o.business.jms  MQDataBusiness
                        JmsSender.setTopicSender(notify);
                    } catch (Exception e) {
                    }
                }
            }
            break;
            default:
                return AjaxResult.errorResult("未知的操作类型");
        }
        return AjaxResult.successResult();
    }

    //用户注册-获取短信验证码 // mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/user/register/getTelCode")
    @ResponseBody
    public String user_register_getTelCode(HttpServletRequest request, String sysAppKey,
                                           String areaCode,// 手机区号
                                           String username, String lang, String ver) {
        if (StringUtils.isNotEmpty(ver) && ver.equals("v2")) {
            // 开始解密username

        }
        // if (null != request) {
        //     Long nowTime = DateUtils.getCurrTime();
        //     String ip = RightFilter.getIpAddr(request);
        //     if (ValidateUtil.isNotNull(ip)) {
        //         if (requestMap.containsKey(ip)) {
        //             Long lastTime = requestMap.get(ip);
        //             if (null == lastTime || nowTime - lastTime > 60 * 1000) {
        //                 // 一分钟后有效
        //                 // 有效的
        //                 requestMap.put(ip, nowTime);
        //             } else {
        //                 return AjaxResult.errorResult("访问过快，请稍后再试");
        //             }
        //         } else {
        //             requestMap.put(ip, nowTime);
        //         }
        //     }
        // }
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
        QueryCondition query = QueryCondition.getInstance();
        if (User.isPhoneLogin()) {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("phone", username));
        } else {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        }
//        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        int count;
        try {
            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
        } catch (SQLException e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
//            return AjaxResult.errorResult("获取用户信息失败，请稍后再试");
        }
        if (count > 0) {
//            return AjaxResult.errorResult("当前手机号已经注册，请直接登录");
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
        }
        // 判断是否需要使用验证码
//        int userRegisterNeedCode = SysSettingMemory.getInstance().getByName(SysSettingKey.USER_REGISTER_NEED_CODE).getVal();
        int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;

        boolean canSend = true;
        //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
        if (userRegisterNeedCode == 1) {
            try {
                canSend = SmsBusiness.getInstance().canSend(username);
            } catch (SmsUserInfoException e) {
//                e.printStackTrace();
                System.out.println(username + "," + e.getMessage());
                return AjaxResult.errorResult(e.getMessage());
            }
        }
        //验证未通过
        if (!canSend) {
//            return AjaxResult.errorResult("您的账号已被限制，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }


        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        document.put("username", username);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式

        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB,
                UserSMSInfoParams.MonUserSMSRegCol, document, upValue, true);
        if (flag == true) {
            if (userRegisterNeedCode == 1) {
//                SMSThreadMap.registerCodeMap.put(username, code);

                JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.REGISTER, code, RightFilter.getIpAddr(request));
            }
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
            return buffer.toString();
        } else {
//            return AjaxResult.errorResult("获取失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.GET_CODE_FAILED, lang);
        }
    }

    //骑手注册-获取短信验证码 // mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/postman/register/getTelCode")
    @ResponseBody
    public String postman_register_getTelCode(HttpServletRequest request, String sysAppKey,
                                              String areaCode,// 手机区号
                                              String username, String lang) {
        if (ValidateUtil.isNull(username)) {
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
        boolean isExactUserType = User.isExactUserType(); // 是否准确的用户类型
//        if (SYS_SETTINGS.OPEN_EXACT_USER_TYPE != null && SYS_SETTINGS.OPEN_EXACT_USER_TYPE == 1) {
//            isExactUserType = true;
//        }
//        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
        // 获取用户信息
        UserInfo userInfo = User.getUserInfoByUsername(username);
        if (null != userInfo) {
            if (null != userInfo.getUserType()) {
                switch (userInfo.getUserType()) {
                    case UserType.USER: {
                        //改为骑手身份
//                        boolean flag = User.modifyUserType(username, UserType.POSTMAN);
                        boolean flag = User.modifyUserType(userInfo.getUsername(), UserType.POSTMAN);
                        if (flag) {
                            return AjaxResult.successResult("您已成为骑手，请重新登录");
                        } else {
                            return AjaxResult.errorResult("您是用户，请联系客服");
                        }
                    }
                    case UserType.POSTMAN: {
                        return AjaxResult.errorResult("该账号为骑手，请登录");
                    }
                    case UserType.SHOP_OWNER: {
                        if (isExactUserType) {
                            return AjaxResult.errorResult("请直接登录");
                        } else {
                            return AjaxResult.errorResult("该账号为商户，无法成为骑手");
                        }
                    }
                    default: {
                        return AjaxResult.errorResult("该账号已经注册为未其他类型的用户，无法成为骑手");
                    }
                }
            } else {
                return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
            }
        }

        // 判断是否需要使用验证码
        int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;

        boolean canSend = true;
        //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
        if (userRegisterNeedCode == 1) {
            try {
                canSend = SmsBusiness.getInstance().canSend(username);
            } catch (SmsUserInfoException e) {
                System.out.println(username + "," + e.getMessage());
                return AjaxResult.errorResult(e.getMessage());
            }
        }
        //验证未通过
        if (!canSend) {
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }

        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        document.put("username", username);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式

        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB,
                UserSMSInfoParams.MonUserSMSRegCol, document, upValue, true);
        if (flag == true) {
            if (userRegisterNeedCode == 1) {
                JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.REGISTER, code, RightFilter.getIpAddr(request));
            }
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
            return buffer.toString();
        } else {
            return MultilingualResult.errorResultV2(PROMPTS.GET_CODE_FAILED, lang);
        }
    }

    //用户注册1 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/user/register/byTelCode")
    @ResponseBody
    public String user_register(String username, String telCode, String password, String province, String city, String county, String sysAppKey, String lang, String email, String devJson) {
        ResultInfo resultInfo = UserLogin.registerByTelCode(username, true, password, telCode, true, email, devJson);//单独注册接口
        if (null == resultInfo) {
//            return AjaxResult.errorResult("注册失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_USER, lang);
        }
        if (null != resultInfo && !resultInfo.isSuccess()) {
//            return AjaxResult.errorResult(resultInfo.getError());
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }

        if (ValidateUtil.isNotNull(province) || ValidateUtil.isNotNull(city) || ValidateUtil.isNotNull(county)) {
            UserInfo userInfo = null;
            if (User.isPhoneLogin()) {
                userInfo = UserInfoMemory.getInstance().getUserInfoByPhone(username);
            } else {
                userInfo = UserInfoMemory.getInstance().getUserInfo(username);
            }
            StringBuilder sql = new StringBuilder();
            sql.append("update ").append(PojoTables.UserInfo).append(" set ")
                    .append(" updateUser = '").append(userInfo.getUsername()).append("'");
            if (ValidateUtil.isNotNull(province)) {
                sql.append(", province ='").append(province).append("'");
            }
            if (ValidateUtil.isNotNull(city)) {
                sql.append(", city ='").append(city).append("'");
            }
            if (ValidateUtil.isNotNull(county)) {
                sql.append(", county ='").append(county).append("'");
            }
            sql.append(" where delFlag = 0 and username = '").append(userInfo.getUsername()).append("'");
            try {
                UserDaoSql.getInstance().executeBySql(sql.toString());
                UserInfoMemory.getInstance().modifyUserInfo(userInfo.getUsername());
            } catch (Exception e) {

            }
        }
        return AjaxResult.successResult();

//        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
//        }
//        if (ValidateUtil.isNull(telCode)) {
//            return AjaxResult.errorResult("验证码不能为空");
//        }
//        //验证是否已经存在当前帐号
//        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
//        int count;
//        try {
//            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return AjaxResult.errorNET2Result();
//        }
//        if (count > 0) {
//            return AjaxResult.errorResult("当前手机号已经注册，请直接登录");
//        }
//        if (telCode == null || telCode.equals("")) {
//            return AjaxResult.errorResult("请填写验证码");
//        } else {
//            // 判断验证码是否正确
//            HashMap<String, Object> map = new HashMap<String, Object>();
//            map.put("username", username);
//            List<HashMap<String, Object>> list = MongoDaoImpl.getInstance()
//                    .find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSRegCol, map, 1);
//            if (list == null || list.size() < 1) {
//                return AjaxResult.errorResult("请获取验证码");
//            }
//            if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
//                return AjaxResult.errorResult("请输入正确的注册码！");
//            }
//        }
//
//        //密码加密处理
//        try {
//            password = EncrypMD5.eccrypt(password);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.errorNETResult();
//        }
//
//        // 直接注册用户
//        String hxAccount = Common.hxName + username;
//        String hxPwd;
//        try {
//            hxPwd = EncrypMD5.eccrypt(username);
//        } catch (NoSuchAlgorithmException e1) {
//            e1.printStackTrace();
//            return AjaxResult.errorNETResult();
//        }
//        //注册用户信息
//        StringBuffer sbBuffer = new StringBuffer("insert into ")
//                .append(PojoTables.UserInfo)
//                .append("(userType,username,telPhone,hxAccount,hxPassword,createTime)values")
//                .append("(").append(UserType.USER).append(",'").append(username).append("','").append(username).append("','")
//                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");
//        //添加用户帐号信息
//        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime)values(")
//                .append("'").append(username).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(")");
//        Connection conn;
//        try {
//            conn = UserDaoSql.getInstance().getConnection();
//        } catch (SQLException e1) {
//            e1.printStackTrace();
//            return AjaxResult.errorNET2Result();
//        }
//        try {
//            conn.setAutoCommit(false);
//
//            UserDaoSql.getInstance().executeBySql(sbBuffer.toString(), conn);
//            UserDaoSql.getInstance().executeBySql(userPasql.toString(), conn);
//
//            // 注册环信帐号
//            EasemobIMUsers.createNewIMUserSingle(new JsonNodeFactory(false)
//                    .objectNode().put("username", hxAccount).put("password", hxPwd));
//
//            conn.commit();
//        } catch (Exception e) {
//            UserDaoSql.getInstance().rollback(conn);
//            e.printStackTrace();
//            return AjaxResult.errorNETResult();
//        } finally {
//            UserDaoSql.getInstance().close(conn);
//        }
//
//        //同步数据--增加帐号
//        UserInfoMemory.getInstance().addUserInfo(username);    //添加新用户
//        UserPwdMemory.getInstance().getPassword(username);    //添加新用户的密码缓存信息
//
//        JMSNotify notify = JMSNotify.getInstance().setType(JMSNotify.UserAdd).setStr01(username);//o2o.business.jms  MQDataBusiness
//        JmsSender.setTopicSender(notify);
//
//        return AjaxResult.successResult();
    }

    //用户登录1 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/user/login/byPassword")
    @ResponseBody
    public String user_login_byPassword(String username, String password, String lang, String devJson) {
//        UserInfoVO infoVO = null;
//        try {
//            infoVO = login(username, password, UserType.USER);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.errorResult(e.getMessage());
//        }

        ResultInfo resultInfo = UserLogin.loginV2(username, password, UserType.USER, devJson);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO infoVO = (UserInfoVO) resultInfo.getObj();

//        ResultInfo info = User.getUserAddress(username);
        ResultInfo info = User.getUserAddress(infoVO.getUsername());
        if (info.isSuccess() && null != info.getObj()) {
            infoVO.setUserAddress((List<UserAddressVO>) info.getObj());
        }

        //如果是配送员的话返回配送员的信息
        if (0 == UserType.POSTMAN - infoVO.getUserType()) {
//            CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(username);
            CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(infoVO.getUsername());
            if (null != cityPostman) {
                CityPostmanVO postmanVO = PostmanMan.getOne(cityPostman);
                infoVO.setPostmanInfo(postmanVO);
            }
        }
//        UserInfoExtra userInfoExtra = UserInfoExtraMemory.getInstance().getByUsername(username);
        UserInfoExtra userInfoExtra = UserInfoExtraMemory.getInstance().getByUsername(infoVO.getUsername());
        if (null != userInfoExtra) {
            infoVO.setUserInfoExtra(userInfoExtra);
            if (ValidateUtil.isNotNull(devJson)) {// 设备信息
                AppDeviceInfoBusiness.userAddDevice(infoVO.getUsername(), devJson);
            }
        }

        JMSNotify jmsNotify = JMSNotify.getInstance().setType(JMSTypeContent.USER_LOGIN).setStr01(username).setStr02(infoVO.getToken());
        JmsSender.setTopicSender(jmsNotify);

        return AjaxResult.successResult(infoVO);
    }

    //用户登录-获取验证码 1
    @RequestMapping(method = RequestMethod.POST, value = {"/user/login/getTelCode", "/postman/login/getTel-code"})
    @ResponseBody
    public String login_getTelCode(HttpServletRequest request, String sysAppKey,
                                   String areaCode,// 手机区号
                                   String username, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
//        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
//        int count;
//        try {
//            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return AjaxResult.errorResult("获取用户信息失败，请稍后再试");
//        }
//        if (count <= 0) {
//            return AjaxResult.errorResult("当前手机号尚未注册，请先注册");
//        }
        // 判断是否需要使用验证码
        int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;

        boolean canSend = true;
        //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
        if (userRegisterNeedCode == 1) {
            try {
                canSend = SmsBusiness.getInstance().canSend(username);
            } catch (SmsUserInfoException e) {
                e.printStackTrace();
                return AjaxResult.errorResult(e.getMessage());
            }
        }
        //验证未通过
        if (!canSend) {
//            return AjaxResult.errorResult("您的账号已被限制，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }


        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        document.put("username", username);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        System.out.println(code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式


        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB,
                UserSMSInfoParams.MonUserSMSLoginCol, document, upValue, true);
        if (flag == true) {
            if (userRegisterNeedCode == 1) {
//                SMSThreadMap.loginCodeMap.put(username, code);

                JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.LOGIN, code, RightFilter.getIpAddr(request));
            }
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
            return buffer.toString();
        } else {
//            return AjaxResult.errorResult("获取失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.GET_CODE_FAILED, lang);
        }
    }

    //用户通过验证码登录 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/user/login/byTelCode")
    @ResponseBody
    public String user_login_by_telCode(String username, String telCode, String lang, String devJson) {

        if (TextUtils.isEmpty(username)) {
//            return AjaxResult.errorResult("用户名不能为空");
            return MultilingualResult.errorResultV2(PROMPTS.USERNAME_NOT_ALLOWED_EMPTY, lang);
        }
        ResultInfo resultInfo;
        if ("admin".equalsIgnoreCase(username) || "15666371607".equalsIgnoreCase(username)) {
            resultInfo = loginV2(username, telCode, UserType.USER, devJson);
        } else {
            resultInfo = UserLogin.loginByTelCode(username, telCode, UserType.USER, devJson);
        }

//        ResultInfo resultInfo = loginByTelCode(username, telCode, UserType.USER);
        if (null == resultInfo) {
//            return AjaxResult.errorResult("登录失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
        }
        if (!resultInfo.isSuccess()) {
//            return AjaxResult.errorResult(resultInfo.getError());
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO infoVO = (UserInfoVO) resultInfo.getObj();


//        ResultInfo info = User.getUserAddress(username);
        ResultInfo info = User.getUserAddress(infoVO.getUsername());
        if (info.isSuccess() && null != info.getObj()) {
            infoVO.setUserAddress((List<UserAddressVO>) info.getObj());
        }

        return AjaxResult.successResult(infoVO);
    }

    // 用户通过验证客户apikey来注册
    @RequestMapping(method = RequestMethod.POST, value = "/user/login/by-appkey")
    @ResponseBody
    public String userRegisAndLogin(String sysAppKey, String encrypApiKey, String username, String password) {
        if (ValidateUtil.isNotMobile(username)) {
            return AjaxResult.errorResult("手机号不能为空");
        }
        if (StringUtils.isEmpty(sysAppKey)) {
            return AjaxResult.errorResult("客户标识不能为空！");
        }
        SysCustomerInfo sysCustomerInfo = SysCustomerCache.getInstance().getInfo(sysAppKey);
        if (sysCustomerInfo == null) {
            return AjaxResult.errorResult("未查询到有效的客户信息！");
        }
        //
        String sysCustomer = ToolUtils.getSize0(sysAppKey, 16);
        UserInfo userInfo = null;
        try {
            String result = EncrypAES.aesDecrypt(encrypApiKey, sysCustomer);
            String[] ss = result.split(";;");
            String appKey = ss[0];
            String userKey = ss[1];
            if (!username.equals(userKey)) {
                return AjaxResult.errorResult("商城用户验证失败！");
            }
            if ((userInfo = UserInfoMemory.getInstance().getUserInfo(username)) == null) {
                // 自动注册普通用户
                ResultInfo resultInfo = UserLogin.registerByTelCode(username, false, password, null, false, null, null);// 单独注册接口
                if (null == resultInfo) {
                    return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_USER, null);
                }
                if (null != resultInfo && !resultInfo.isSuccess()) {
                    return MultilingualResult.errorResultV2(resultInfo.getError(), null);
                }
            }
        } catch (Exception e) {
            return AjaxResult.errorResult("商城用户登录失败！");
        }

        // 返回用户登录信息
        UserInfoVO userInfoVO = UserLogin.loginNotCheck(username);

        return AjaxResult.successResult(userInfoVO);
    }

    // 用户通过账号和秘钥来注册
    @RequestMapping(method = RequestMethod.POST, value = "/user/regis-login/by-apikey")
    @ResponseBody
    public String userRegisAndLogin(String sysAppKey, String apiKey, String username) {
        if (ValidateUtil.isNull(username)) {
            return AjaxResult.errorResult("账号不能为空");
        }
        if (ValidateUtil.isNull(sysAppKey)) {
            return AjaxResult.errorResult("客户标识不能为空！");
        }
        SysCustomerInfo sysCustomerInfo = SysCustomerCache.getInstance().getInfo(sysAppKey);
        if (sysCustomerInfo == null) {
            return AjaxResult.errorResult("未查询到有效的客户信息！");
        } else {
            if (!apiKey.equals(sysCustomerInfo.getApiKey())) {
                return AjaxResult.errorResult("您没有访问权限");
            }
        }
        //
//        String sysCustomer = ToolUtils.getSize0(sysAppKey, 16);
        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
        if (userInfo == null) {
//            String password = username.substring(username.length() - 6);
            String password = "123456";
            if (ValidateUtil.isNull(username) || username.length() < 6) {

            } else {
                password = username.substring(username.length() - 6);
            }
            // 自动注册普通用户
            ResultInfo resultInfo = UserLogin.registerByTelCode(username, false, password, null, false, null, null);// 单独注册接口
            if (null == resultInfo) {
                return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_USER, null);
            }
            if (null != resultInfo && !resultInfo.isSuccess()) {
                return MultilingualResult.errorResultV2(resultInfo.getError(), null);
            }
        }
//        try {
//
//        } catch (Exception e) {
//            return AjaxResult.errorResult("用户登录失败！");
//        }

        // 返回用户登录信息
        UserInfoVO userInfoVO = UserLogin.loginNotCheck(username);

        return AjaxResult.successResult(userInfoVO);
    }

    /**
     * --------------------
     */
    //找回密码-获取短信验证码 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/user/password/getTelCode")
    @ResponseBody
    public String user_findPassword_getTelCode(HttpServletRequest request, String sysAppKey,
                                               String areaCode,// 手机区号
                                               String username, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
//        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
//        int count;
//        try {
//            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return AjaxResult.errorResult("获取用户信息失败，请稍后再试");
//        }
//        if (count <= 0) {
//            return AjaxResult.errorResult("当前手机号尚未注册，请先注册");
//        }

//        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
        UserInfo userInfo = User.getUserInfoByUsername(username);
        if (null == userInfo) {
//            return AjaxResult.errorResult("当前手机号尚未注册，请先注册");
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_NOT_REGISTER, lang);
        }
        if (User.isLocked(userInfo.getIsLock())) {
//            return AjaxResult.errorResult("您的账号已被锁定，请联系客服解锁");
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }


        // 判断是否需要使用验证码
//        int userRegisterNeedCode = SysSettingMemory.getInstance().getByName(SysSettingKey.USER_REGISTER_NEED_CODE).getVal();
        int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;

        boolean canSend = true;
        //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
        if (userRegisterNeedCode == 1) {
            try {
                canSend = SmsBusiness.getInstance().canSend(username);
            } catch (SmsUserInfoException e) {
                e.printStackTrace();
                return AjaxResult.errorResult(e.getMessage());
            }
        }
        //验证未通过
        if (!canSend) {
//            return AjaxResult.errorResult("您的账号已被限制，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }


        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        document.put("username", username);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式

        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSPasswdCol, document, upValue, true);
        if (flag == true) {
            if (userRegisterNeedCode == 1) {
//                SMSThreadMap.pwdModCodeMap.put(username, code);

                JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.MODIFY_PASSWORD, code, RightFilter.getIpAddr(request));
            }
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
            return buffer.toString();
        } else {
//            return AjaxResult.errorResult("获取失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
        }
    }

    //用户修改密码 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/user/password/modify")
    @ResponseBody
    public String userModifyPassword(String username, String telCode, String password, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
        if (ValidateUtil.isNull(telCode)) {
//            return AjaxResult.errorResult("修改密码失败，验证码不能为空");
            return MultilingualResult.errorResultV2(PROMPTS.CHANGE_PASSWORD_CODE_EMPTY, lang);
        }
        UserInfo user = User.getUserInfoByUsername(username);
        if (user == null) {
            return AjaxResult.errorResult("当前用户未注册");
        }
        //验证是否已经存在当前帐号
        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", user.getUsername()));
        int count;
        try {
            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
        } catch (SQLException e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("修改失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.MODIFICATION_PASSWORD_FAILED, lang);
        }
        if (count <= 0) {
//            return AjaxResult.errorResult("当前手机号尚未注册，请先注册");
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_NOT_REGISTER, lang);
        }
        if (telCode == null || telCode.equals("")) {
//            return AjaxResult.errorResult("修改密码失败，请填写验证码");
            return MultilingualResult.errorResultV2(PROMPTS.CHANGE_PASSWORD_CODE_EMPTY, lang);
        } else {
            // 判断验证码是否正确
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("username", username);
            List<HashMap<String, Object>> list = MongoDaoImpl.getInstance()
                    .find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSPasswdCol, map, 1);
            if (list == null || list.size() < 1) {
//                return AjaxResult.errorResult("请获取验证码");
                return MultilingualResult.errorResultV2(PROMPTS.GET_VERIFICATION_CODE, lang);
            }
            // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
            if (list.get(0).get("telCode") == null
                    || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
//                return AjaxResult.errorResult("请输入正确的验证码！");
                return MultilingualResult.errorResultV2(PROMPTS.ENTER_CORRECT_VERIFY_CODE, lang);
            }
        }

        // 密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("转化密码错误，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.PASSWORD_ENCRYPTION_FAILED, lang);
        }

        //修改密码
//        if (!modifyUserPassword(username, password)) {
        if (!User.modifyUserPassword(user.getUsername(), password)) {
//            AjaxResult.errorResult("修改密码失败，请稍后再试");
            MultilingualResult.errorResultV2(PROMPTS.MODIFICATION_PASSWORD_FAILED, lang);
        }
        // 修改缓存
        UserPwdMemory.getInstance().modifyPassword(user.getUsername(), password);
        //同步修改密码
//        JMSNotify notify = JMSNotify.getInstance().setType(JMSNotify.UserPasswordModify).setStr01(username).setStr02(password);//o2o.business.jms  MQDataBusiness
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_PASSWORD_MODIFY).setStr01(user.getUsername()).setStr02(password);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);

        return AjaxResult.successResult();
    }

    /**
     * ---------------
     */
    // 注销获取验证码
    @RequestMapping(method = RequestMethod.POST, value = {"/user/account/cancel/getTelCode", "/shop/account/cancel/getTelCode", "/postman/account/cancel/getTelCode"})
    @ResponseBody
    public String user_cancel_getTelCode(HttpServletRequest request, String sysAppKey,
                                         String areaCode,// 手机区号
                                         String username, String lang) {
        if (ValidateUtil.isNull(username)) {
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
        UserInfo userInfo = User.getUserInfoByUsername(username);
        if (null == userInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_NOT_REGISTER, lang);
        }
        if (User.isLocked(userInfo.getIsLock())) {
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }
        // 判断是否需要使用验证码
        int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;

        boolean canSend = true;
        //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
        if (userRegisterNeedCode == 1) {
            try {
                canSend = SmsBusiness.getInstance().canSend(username);
            } catch (SmsUserInfoException e) {
                e.printStackTrace();
                return AjaxResult.errorResult(e.getMessage());
            }
        }
        //验证未通过
        if (!canSend) {
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }

        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        document.put("username", username);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式

        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSCancelCol, document, upValue, true);
        if (flag == true) {
            if (userRegisterNeedCode == 1) {
                JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.ACCOUNT_CANCEL, code, RightFilter.getIpAddr(request));
            }
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
            return buffer.toString();
        } else {
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
        }
    }

    // 注销账号-用户
    @RequestMapping(method = RequestMethod.POST, value = "/user/account/cancel")
    @ResponseBody
    public String userCancel(String username, String telCode, String lang) {
        ResultInfo resultInfo = User.cancelAccount(UserType.USER, username, telCode, lang);
        if (null != resultInfo) {
            if (!resultInfo.isSuccess()) {
                return AjaxResult.errorResult(resultInfo.getError());
            }
        } else {
            return AjaxResult.errorResult("注销失败，请稍后再试");
        }
        return AjaxResult.successResult();
    }

    // 注销账号
    @RequestMapping(method = RequestMethod.POST, value = "/shop/account/cancel")
    @ResponseBody
    public String shopCancel(String username, String telCode, String lang) {
        ResultInfo resultInfo = User.cancelAccount(UserType.SHOP_OWNER, username, telCode, lang);
        if (null != resultInfo) {
            if (!resultInfo.isSuccess()) {
                return AjaxResult.errorResult(resultInfo.getError());
            }
        } else {
            return AjaxResult.errorResult("注销失败，请稍后再试");
        }
        return AjaxResult.successResult();
    }

    // 注销账号
    @RequestMapping(method = RequestMethod.POST, value = "/postman/account/cancel")
    @ResponseBody
    public String postmanCancel(String username, String telCode, String lang) {
        ResultInfo resultInfo = User.cancelAccount(UserType.POSTMAN, username, telCode, lang);
        if (null != resultInfo) {
            if (!resultInfo.isSuccess()) {
                return AjaxResult.errorResult(resultInfo.getError());
            }
        } else {
            return AjaxResult.errorResult("注销失败，请稍后再试");
        }
        return AjaxResult.successResult();
    }

    //--------用户是否登录过
    @RequestMapping(method = RequestMethod.POST, value = "/user/username/check")
    @ResponseBody
    public String user_password(String sysAppKey, String username, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }

        UserInfo userInfo = User.getUserInfoByUsername(username);
        if (null == userInfo) {
//            return AjaxResult.errorResult("当前手机号尚未注册，请先注册");
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_NOT_REGISTER, lang);
        }
        if (User.isLocked(userInfo.getIsLock())) {
//            return AjaxResult.errorResult("您的账号已被锁定，请联系客服解锁");
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }

        // 获取用户密码
        UserPasswordInfo password = UserPwdMemory.getInstance().getByUsername(username);
        if (null != password && null != password.getHasSetPsw() && 0 == 1 - password.getHasSetPsw()) {
            return AjaxResult.successResult();
        } else {
            return AjaxResult.errorResult("您尚未设置密码，请先设置密码", AjaxResult.ErrorType_First_Login);
        }
//        if (ValidateUtil.isNull(password) || password.equalsIgnoreCase(oneP)) {
//            // 首次登陆
//            return AjaxResult.errorResult("您尚未设置密码，请先设置密码", AjaxResult.ErrorType_First_Login);
//        } else {
//            return AjaxResult.successResult();
//        }
    }

    //--------------------根据环信账号获取用户信息
    //根据环信账号获取用户信息
    @RequestMapping(method = RequestMethod.POST, value = "/user/hx/list")
    @ResponseBody
    public String user_list_of_hx(String token, String username, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请输入要查询的账号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_ACCOUNT_QUERY, lang);
        }

        List<UserInfoVO> list = new ArrayList<UserInfoVO>();

        String[] users = username.split(",");
        for (int i = 0; i < users.length; i++) {
            if (ValidateUtil.isNull(users[i])) {
                continue;
            }
            String usern = users[i].replace(Common.hxName, "");
            UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(usern);
            if (null == userInfo) {
                continue;
            }
            UserInfoVO infoVO = new UserInfoVO();
            try {
                ObjectUtils.copyPropertiesExclude(userInfo, infoVO, null);
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
            if (null == infoVO) {
                continue;
            }

            if (ValidateUtil.isNotNull(infoVO.getSignPhoto()) && ValidateUtil.isNotNetUrl(infoVO.getSignPhoto())) {
                infoVO.setSignPhoto(SYS_CONFIG_PATH.IMAGE_BASE_URL + infoVO.getSignPhoto());
            }

            list.add(infoVO);
        }

        if (ValidateUtil.isAbsList(list)) {
            return AjaxResult.successResult(list.size(), list);
        }
        return AjaxResult.successResult(0, null);
    }


    //====================================店家
    //用户注册-获取短信验证码 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/shop/register/getTelCode")
    @ResponseBody
    public String shop_register_getTelCode(HttpServletRequest request, String sysAppKey,
                                           String areaCode,// 手机区号
                                           String username, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
//        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
//        int count;
//        try {
//            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
//        } catch (SQLException e) {
//            e.printStackTrace();
////            return AjaxResult.errorResult("获取用户信息失败，请稍后再试");
//            return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
////            return AjaxResult.errorResult("获取用户信息失败，请稍后再试");
//        }
//        if (count > 0) {
////            return AjaxResult.errorResult("当前手机号已经注册，请直接登录");
//            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
//        }
        boolean isExactUserType = User.isExactUserType(); // 是不是准确的权限

//        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
        UserInfo userInfo = User.getUserInfoByUsername(username);
        if (null != userInfo) {
            if (null != userInfo.getUserType()) {
                switch (userInfo.getUserType()) {
                    case UserType.USER: {
                        //改为店主身份
//                        boolean flag = User.modifyUserType(username, UserType.SHOP_OWNER);
                        boolean flag = User.modifyUserType(userInfo.getUsername(), UserType.SHOP_OWNER);
                        if (flag) {
                            return AjaxResult.errorResult("您已成为店主，请重新登录");
                        } else {
                            return AjaxResult.errorResult("您是用户，请联系客服");
                        }
                    }
                    case UserType.POSTMAN: {
                        if (isExactUserType) {
                            return AjaxResult.errorResult("您已经注册，请重新登录");
                        } else {
                            return AjaxResult.errorResult("该账号为骑手，无法成为店主");
                        }

                    }
                    case UserType.SHOP_OWNER: {
                        return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
                    }
                    default: {
                        return AjaxResult.errorResult("该账号已经注册为未其他类型的用户，无法成为店主");
                    }

                }
            } else {
                return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
            }
        }
        // 判断是否需要使用验证码
//        int userRegisterNeedCode = SysSettingMemory.getInstance().getByName(SysSettingKey.USER_REGISTER_NEED_CODE).getVal();
        int userRegisterNeedCode = SYS_SETTINGS.USER_REGISTER_NEED_CODE;

        boolean canSend = true;
        //验证当前手机号是否还可以发送短信(日发送量及发送间隔)
        if (userRegisterNeedCode == 1) {
            try {
                canSend = SmsBusiness.getInstance().canSend(username);
            } catch (SmsUserInfoException e) {
//                e.printStackTrace();
                System.out.println(username + "," + e.getMessage());
                return AjaxResult.errorResult(e.getMessage());
            }
        }
        //验证未通过
        if (!canSend) {
//            return AjaxResult.errorResult("您的账号已被限制，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.ACCOUNT_IS_LOCKED, lang);
        }


        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        document.put("username", username);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式

        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB,
                UserSMSInfoParams.MonUserSMSRegCol, document, upValue, true);
        if (flag == true) {
            if (userRegisterNeedCode == 1) {
                JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.REGISTER, code, RightFilter.getIpAddr(request));
            }
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(userRegisterNeedCode == 1 ? 0 : 1).append(",\"telCode\":\"").append(userRegisterNeedCode == 1 ? "" : code).append("\"}");
            return buffer.toString();
        } else {
            return MultilingualResult.errorResultV2(PROMPTS.GET_CODE_FAILED, lang);
        }
    }


    //店家注册  只注册账号不生成店铺 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/shop/register/byTelCode")
    @ResponseBody
    public String shop_register(String username, String telCode, String password, String lang) {
        if (ValidateUtil.isNull(username)) {
//            return AjaxResult.errorResult("请先输入手机号");
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
        if (ValidateUtil.isNull(telCode)) {
//      return AjaxResult.errorResult("注册失败，验证码不能为空。");
            return MultilingualResult.errorResultV2(PROMPTS.VERIFICATION_CODE_EMPTY, lang);
        }
        //验证是否已经存在当前帐号
        QueryCondition query = QueryCondition.getInstance();
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        if (User.isPhoneLogin()) {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("phone", username));
        } else {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        }
        int count;
        try {
            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
        } catch (SQLException e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("注册失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_USER, lang);
        }
        if (count > 0) {
//            return AjaxResult.errorResult("当前手机号已经注册，请直接登录");
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
        }
        if (telCode == null || telCode.equals("")) {
//            return AjaxResult.errorResult("注册失败，请先填写验证码");
            return MultilingualResult.errorResultV2(PROMPTS.VERIFICATION_CODE_EMPTY, lang);
        } else {
            // 判断验证码是否正确
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("username", username);
            List<HashMap<String, Object>> list = MongoDaoImpl.getInstance()
                    .find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSRegCol, map, 1);
            if (list == null || list.size() < 1) {
//                return AjaxResult.errorResult("请获取验证码");
                return MultilingualResult.errorResultV2(PROMPTS.GET_VERIFICATION_CODE, lang);
            }
            // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
            if (list.get(0).get("telCode") == null
                    || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
//                return AjaxResult.errorResult("请输入正确的验证码！");
                return MultilingualResult.errorResultV2(PROMPTS.ENTER_CORRECT_VERIFY_CODE, lang);
            }
        }

        String realUsername = User.getUniqueUserName(username);
        if (StringUtils.isEmpty(realUsername)) {
            return AjaxResult.errorResult("新建失败,请稍后重试");
        }
        //密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("转化密码错误，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.PASSWORD_ENCRYPTION_FAILED, lang);
        }

        // 直接注册用户
//        String hxAccount = Common.hxName + username;
        String hxAccount = Common.hxName + realUsername;
        String hxPwd;
        try {
//            hxPwd = EncrypMD5.eccrypt(username);
            hxPwd = EncrypMD5.eccrypt(realUsername);
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
//            return AjaxResult.errorResult("加密环信账号失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.ENCRYPTED_ACCOUNT_FAILED, lang);
        }
        //注册用户信息
//        StringBuffer sbBuffer = new StringBuffer("insert into ")
//                .append(PojoTables.UserInfo)
//                .append("(userType,username,telPhone,hxAccount,hxPassword,createTime)values")
//                .append("(").append(UserType.SHOP_OWNER).append(",'").append(username).append("','").append(username).append("','")
//                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");
        StringBuffer sbBuffer = new StringBuffer("insert into ")
                .append(PojoTables.UserInfo)
                .append("(userType,username,phone,telPhone,hxAccount,hxPassword,createTime)values")
                .append("(").append(UserType.SHOP_OWNER).append(",'").append(realUsername).append("'").append(",'").append(username).append("','").append(username).append("','")
                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");
        //添加用户帐号信息
//        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime)values(")
//                .append("'").append(username).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(")");
        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime)values(")
                .append("'").append(realUsername).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(")");
        Connection conn;
        try {
            conn = UserDaoSql.getInstance().getConnection();
        } catch (SQLException e1) {
            e1.printStackTrace();
//            return AjaxResult.errorResult("注册失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_ENCRYPTED_ACCOUNT, lang);
        }
        try {
            conn.setAutoCommit(false);

            UserDaoSql.getInstance().executeBySql(sbBuffer.toString(), conn);
            UserDaoSql.getInstance().executeBySql(userPasql.toString(), conn);

            conn.commit();
        } catch (Exception e) {
            UserDaoSql.getInstance().rollback(conn);
            e.printStackTrace();
//            return AjaxResult.errorResult("注册环信账号失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_ENCRYPTED_ACCOUNT, lang);
        } finally {
            UserDaoSql.getInstance().close(conn);
        }

        //同步数据--增加帐号
//        UserInfoMemory.getInstance().addUserInfo();    //添加新用户
        UserInfoMemory.getInstance().addUserInfo(realUsername);    //添加新用户
//        UserPwdMemory.getInstance().getPassword(username);    //添加新用户的密码缓存信息
        UserPwdMemory.getInstance().getPassword(realUsername);    //添加新用户的密码缓存信息

        try {
            JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_ADD).setStr01(realUsername);
            JmsSender.setTopicSender(notify);
        } catch (Exception e) {
        }



        return AjaxResult.successResult();
    }


    //店家登录 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/shoper/login/byPassword")
    @ResponseBody
    public String shoper_login_byPassword(String username, String password, String lang, String devJson) {
        ResultInfo resultInfo = loginV2(username, password, UserType.SHOP_OWNER, devJson);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO userInfoVO = (UserInfoVO) resultInfo.getObj();

        UserInfoShoperVO infoVO = new UserInfoShoperVO();
        try {
            ObjectUtils.copyPropertiesExclude(userInfoVO, infoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
        }
        List<ShopInfo> list = ShopMemory.getInstance().getShopListByUserName(userInfoVO.getUsername());
        if (ValidateUtil.isAbsList(list)) {
            List<ShopInfoVO> voList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }

                //0 锁定  1正常
                if (0 == list.get(i).getIsLock()) {
                    return MultilingualResult.errorResultV2(PROMPTS.STORE_IS_LOCKED, lang);
                }
                ShopInfoVO infoVO1 = new ShopInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), infoVO1, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
                }
                ShopInfoExtra shopInfoExtra = ShopExtraInfoMemory.getInstance().getShopExtraInfoById(list.get(i).getId());
                if (shopInfoExtra != null) {
                    infoVO1.setShopCategoryApplyState(shopInfoExtra.getShopCategoryApplyState())
                            .setCloudShopApplyState(shopInfoExtra.getCloudShopApplyState());
                }
                //店铺行业信息
                List<ShopTypeInfoVO> typeInfoVOList = null;

                if (ValidateUtil.isAbsList(typeInfoVOList)) {
                    infoVO1.setShopType(typeInfoVOList);
                }
                voList.add(infoVO1);
            }
            if (null != list && list.size() > 0) {
                infoVO.setShop(voList);
            }
        }
        //代理信息
        CityAgent cityAgent = CityAgentMemory.getInstance().getByUsername(infoVO.getUsername());
        if (null != cityAgent) {
            CityAgentVO cityAgentVO = new CityAgentVO();
            try {
                ObjectUtils.copyPropertiesExclude(cityAgent, cityAgentVO, null);
            } catch (Exception e) {
                e.printStackTrace();
                cityAgentVO = null;
            }

            if (null != cityAgentVO) {
                infoVO.setAgent(cityAgentVO);
            }
        }


        return AjaxResult.successResult(infoVO);
    }

    //===================================配送员
    //配送注册  只注册账号不生成配送 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/postman/register/byTelCode")
    @ResponseBody
    public String postman_register(String username, String telCode, String password, String lang) {
        if (ValidateUtil.isNull(username)) {
            return MultilingualResult.errorResultV2(PROMPTS.ENTER_YOUR_MOBILE, lang);
        }
        if (ValidateUtil.isNull(telCode)) {
            return MultilingualResult.errorResultV2(PROMPTS.VERIFICATION_CODE_EMPTY, lang);
        }
        //验证是否已经存在当前帐号
        QueryCondition query = QueryCondition.getInstance();
        if (User.isPhoneLogin()) {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("phone", username));
        } else {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        }
//        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        int count;
        try {
            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
        } catch (SQLException e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_USER, lang);
        }
        if (count > 0) {
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_IS_ALREADY, lang);
        }
        if (telCode == null || telCode.equals("")) {
            return MultilingualResult.errorResultV2(PROMPTS.VERIFICATION_CODE_EMPTY, lang);
        } else {
            // 判断验证码是否正确
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("username", username);
            List<HashMap<String, Object>> list = MongoDaoImpl.getInstance()
                    .find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSRegCol, map, 1);
            if (list == null || list.size() < 1) {
                return MultilingualResult.errorResultV2(PROMPTS.GET_VERIFICATION_CODE, lang);
            }
            // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
            if (list.get(0).get("telCode") == null
                    || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
                return MultilingualResult.errorResultV2(PROMPTS.ENTER_CORRECT_VERIFY_CODE, lang);
            }
        }

        String realUsername = User.getUniqueUserName(username);
        if (StringUtils.isEmpty(realUsername)) {
            return AjaxResult.errorResult("新建失败,请稍后重试");
        }
        //密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.PASSWORD_ENCRYPTION_FAILED, lang);
        }

        // 直接注册用户
        String hxAccount = Common.hxName + realUsername;
//        String hxAccount = Common.hxName + username;
        String hxPwd;
        try {
//            hxPwd = EncrypMD5.eccrypt(username);
            hxPwd = EncrypMD5.eccrypt(realUsername);
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.ENCRYPTED_ACCOUNT_FAILED, lang);
        }
        //注册用户信息
//        StringBuffer sbBuffer = new StringBuffer("insert into ")
//                .append(PojoTables.UserInfo)
//                .append("(userType,username,telPhone,hxAccount,hxPassword,createTime)values")
//                .append("(").append(UserType.POSTMAN).append(",'").append(username).append("','").append(username).append("','")
//                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");
        StringBuffer sbBuffer = new StringBuffer("insert into ")
                .append(PojoTables.UserInfo)
                .append("(userType,username,phone,telPhone,hxAccount,hxPassword,createTime)values")
                .append("(").append(UserType.POSTMAN).append(",'").append(realUsername).append("'").append(",'").append(username).append("','").append(username).append("','")
                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");
        //添加用户帐号信息
//        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime)values(")
//                .append("'").append(username).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(")");
        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime)values(")
                .append("'").append(realUsername).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(")");
        Connection conn;
        try {
            conn = UserDaoSql.getInstance().getConnection();
        } catch (SQLException e1) {
            e1.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_ENCRYPTED_ACCOUNT, lang);
        }
        try {
            conn.setAutoCommit(false);
            UserDaoSql.getInstance().executeBySql(sbBuffer.toString(), conn);
            UserDaoSql.getInstance().executeBySql(userPasql.toString(), conn);

            conn.commit();
        } catch (Exception e) {
            UserDaoSql.getInstance().rollback(conn);
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_ENCRYPTED_ACCOUNT, lang);
        } finally {
            UserDaoSql.getInstance().close(conn);
        }

        //同步数据--增加帐号
        UserInfoMemory.getInstance().addUserInfo(realUsername);    //添加新用户
        UserPwdMemory.getInstance().getPassword(realUsername);    //添加新用户的密码缓存信息

        try {
            JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_ADD).setStr01(realUsername);//o2o.business.jms  MQDataBusiness
            JmsSender.setTopicSender(notify);
        } catch (Exception e) {
        }

        return AjaxResult.successResult();
    }

    //配送员登录 mod 1
    @RequestMapping(method = RequestMethod.POST, value = {"/postman/login/byPassword", "secondary/postman/login/byPassword"})
    @ResponseBody
    @ApiOperation("骑手端登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户名",required = true),
            @ApiImplicitParam(name = "password",value = "密码",required = true),
    })
    public String postman_login_byPassword(String username, String password, HttpServletRequest request, String lang, String devJson) {
//        UserInfoVO infoVO = null;
//        try {
//            infoVO = login(username, password, UserType.USER);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.errorResult(e.getMessage());
//        }

        ResultInfo resultInfo = loginV2(username, password, UserType.POSTMAN, devJson);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO userInfoVO = (UserInfoVO) resultInfo.getObj();

        UserInfoPostmanVO infoVO = new UserInfoPostmanVO();
        try {
            ObjectUtils.copyPropertiesExclude(userInfoVO, infoVO);
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
        }
//        CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(username);
        CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(userInfoVO.getUsername());
        if (null != cityPostman) {
            if (cityPostman.getIsLock() != null && cityPostman.getIsLock() == 1) {
                return AjaxResult.errorResult("您已被锁定,请联系客服");
            }
            // 二级骑手登录
            if (request.getRequestURI().contains("secondary")) {
                if (cityPostman.getType() != null && cityPostman.getType() != POSTMAN_TYPE.POSTMAN_2) {
                    return AjaxResult.errorResult("您不是众包骑手");
                }
            } else {
                if (cityPostman.getType() != null && cityPostman.getType() == POSTMAN_TYPE.POSTMAN_2) {
                    return AjaxResult.errorResult("你是众包骑手,无法登录");
                }
            }
            CityPostmanVO vo = new CityPostmanVO();
            try {
                ObjectUtils.copyPropertiesExclude(cityPostman, vo);
            } catch (Exception e) {
                e.printStackTrace();
                vo = null;
            }
            infoVO.setPostman(vo);
        }

        return AjaxResult.successResult(infoVO);
    }


    // 骑手-通过验证码登录
    @RequestMapping(method = RequestMethod.POST, value = {"/postman/login/byTelCode"})
    @ResponseBody
    public String postman_login_by_tel_code(String username, String telCode, HttpServletRequest request, String lang, String devJson) {
        ResultInfo resultInfo = UserLogin.loginByTelCode(username, telCode, UserType.POSTMAN, devJson);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO userInfoVO = (UserInfoVO) resultInfo.getObj();
        UserInfoPostmanVO infoVO = new UserInfoPostmanVO();
        BeanUtils.copyProperties(userInfoVO, infoVO);
        CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(userInfoVO.getUsername());
        if (null != cityPostman) {
            if (cityPostman.getIsLock() != null && cityPostman.getIsLock() == 1) {
                return AjaxResult.errorResult("您已被锁定,请联系客服");
            }
            // 二级骑手登录
            if (request.getRequestURI().contains("secondary")) {
                if (cityPostman.getType() != null && cityPostman.getType() != POSTMAN_TYPE.POSTMAN_2) {
                    return AjaxResult.errorResult("您不是众包骑手");
                }
            } else {
                if (cityPostman.getType() != null && cityPostman.getType() == POSTMAN_TYPE.POSTMAN_2) {
                    return AjaxResult.errorResult("你是众包骑手,无法登录");
                }
            }
            CityPostmanVO vo = new CityPostmanVO();
            BeanUtils.copyProperties(cityPostman, vo);
            infoVO.setPostman(vo);
        }
        return AjaxResult.successResult(infoVO);
    }


    //===================================其他用户登录 mod 1
    @RequestMapping(method = RequestMethod.POST, value = "/other/user/login/byPassword")
    @ResponseBody
    public String other_login_byPassword(String username, String password, Integer userType, String devJson) {
        if (null == userType) {
            return AjaxResult.errorResult("用户类型不能为空");
        }
        ResultInfo resultInfo = loginV2(username, password, userType, devJson);
        if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }
        UserInfoVO infoVO = (UserInfoVO) resultInfo.getObj();

        return AjaxResult.successResult(infoVO);
    }


    //====================================管理员
    //管理员登录 mod
    @RequestMapping(method = RequestMethod.POST, value = "/admin/login/byPassword")
    @ResponseBody
    public String admin_login_byPassword(String username, String password, String lang, String devJson) {
//        UserInfoVO infoVO = null;
//        try {
//            infoVO = login(username, password, UserType.ADMIN);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.errorResult(e.getMessage());
//        }

        ResultInfo resultInfo = loginV2(username, password, UserType.ADMIN, devJson);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO infoVO = (UserInfoVO) resultInfo.getObj();

//        List<SysCityAdmin> sysCityAdminList = SysCityAdminMemory.getInstance().listOfUsername(username);
//        List<SysCityAdmin> sysCityAdminList = SysCityAdminMemory.getInstance().listOfUsername(infoVO.getUsername());

        UserInfoAgentVO agentVO = new UserInfoAgentVO();
        try {
            ObjectUtils.copyPropertiesExclude(infoVO, agentVO, null);
        } catch (Exception e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("登录失败，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.ADMIN_LOGIN_FAILED, lang);
        }
        String tempUsername = infoVO.getUsername();
        UserRoleAuthInfoVO roleAuthInfoVO = AuthRoleMan.getUserRoleAuthRoleByUsername(infoVO.getUsername(), infoVO.getUserType());
        if (roleAuthInfoVO != null) {
            agentVO.setAuthInfos2(roleAuthInfoVO.getAuthInfoList2());
        }
        if (infoVO.getUserType() == UserType.SUPER_COMPANY || infoVO.getUserType() == UserType.COMPANY) {
            tempUsername = SysCityCompanyMan.getSysCompanyOwnUsername(tempUsername);
        }

        //代理信息
//        CityAgent cityAgent = CityAgentMemory.getInstance().getByUsername(username);
//        CityAgent cityAgent = CityAgentMemory.getInstance().getByUsername(infoVO.getUsername());
        CityAgent cityAgent = CityAgentMemory.getInstance().getByUsername(tempUsername);
        if (null != cityAgent) {
            CityAgentVO cityAgentVO = new CityAgentVO();
            try {
                ObjectUtils.copyPropertiesExclude(cityAgent, cityAgentVO, null);
            } catch (Exception e) {
                e.printStackTrace();
                cityAgentVO = null;
            }

            if (null != cityAgentVO) {
                agentVO.setAgent(cityAgentVO);
            }
        }
//        UserInfoExtra userInfoExtra = UserInfoExtraMemory.getInstance().getByUsername(username);
        UserInfoExtra userInfoExtra = UserInfoExtraMemory.getInstance().getByUsername(infoVO.getUsername());
        if (null != userInfoExtra) {
            agentVO.setUserInfoExtra(userInfoExtra);
        }
        // add by yangtk 2019年7月16日18:22:29
//        if (SysCityAdminMan.isCreateCompanyByCreateSysCityAdmin()) {
//            UserRoleAuthInfoVO roleAuthInfoVO = AuthRoleMan.getUserRoleAuthRoleByUsername(infoVO.getUsername(), infoVO.getUserType());
//            if (roleAuthInfoVO != null) {
//                agentVO.setAuthInfos2(roleAuthInfoVO.getAuthInfoList2());
//            }
////            agentVO.setRoleAuthInfo(roleAuthInfoVO);
//        }
        return AjaxResult.successResult(agentVO);
    }

    //====================================管理员
    // 配送公司登录 mod
    @RequestMapping(method = RequestMethod.POST, value = "/post/company/login/byPassword")
    @ResponseBody
    public String post_company_login_byPassword(String username, String password, String lang) {
        ResultInfo resultInfo = loginV2(username, password, UserType.POST_COMPANY, null);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO infoVO = (UserInfoVO) resultInfo.getObj();

        if (infoVO.getUserType() != UserType.POST_COMPANY) {
            return AjaxResult.errorResult("您没有权限登录");
        }
        UserPostCompanyVO postCompanyVO = new UserPostCompanyVO();
        try {
            ObjectUtils.copyPropertiesExclude(infoVO, postCompanyVO, null);
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.ADMIN_LOGIN_FAILED, lang);
        }
        // 配送公司
        PostCompanyInfo postCompanyInfo = PostCompanyMemory.getInstance().getByUsername(infoVO.getUsername());
        if (postCompanyInfo == null) {
            return AjaxResult.errorResult("未查询到您的公司,请联系客服");
        }
        PostCompanyInfoVO companyInfoVO = new PostCompanyInfoVO();
        try {
            ObjectUtils.copyPropertiesExclude(postCompanyInfo, companyInfoVO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("请稍后重试");
        }
        postCompanyVO.setPostCompanyInfo(companyInfoVO);
        // 额外信息
        UserInfoExtra userInfoExtra = UserInfoExtraMemory.getInstance().getByUsername(infoVO.getUsername());
        if (null != userInfoExtra) {
            postCompanyVO.setUserInfoExtra(userInfoExtra);
        }
        return AjaxResult.successResult(postCompanyVO);
    }


    //管理员修改密码
    @RequestMapping(method = RequestMethod.POST, value = "/admin/password/modify")
    @ResponseBody
    public String adminModifyPassword(String token, String oldPassword, String password, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (ValidateUtil.isNull(oldPassword)) {
//            return AjaxResult.errorResult("请先输入原密码");
            return MultilingualResult.errorResultV2(PROMPTS.INPUT_ORIGINAL_PASSWORD, lang);
        }
        if (ValidateUtil.isNull(password)) {
//            return AjaxResult.errorResult("请先输入新密码");
            return MultilingualResult.errorResultV2(PROMPTS.INPUT_NEW_PASSWORD, lang);
        }
        //验证是否已经存在当前帐号
        QueryCondition query = QueryCondition.getInstance();
        query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", user.getUsername()));
        int count;
        try {
            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
        } catch (SQLException e) {
            e.printStackTrace();
//      return AjaxResult.errorResult("修改失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.MODIFICATION_PASSWORD_FAILED, lang);
        }
        if (count <= 0) {
//            return AjaxResult.errorResult("当前手机号尚未注册，请先注册");
            return MultilingualResult.errorResultV2(PROMPTS.MOBILE_NOT_REGISTER, lang);
        }

        //验证是否可以登录管理端
        int userType = user.getUserType();
        if (0 == userType - UserType.USER) {
//            return AjaxResult.errorResult("您没有登录管理后台的权限，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.NO_ADMINISTRATIVE, lang);
        }

        String rpassword = UserPwdMemory.getInstance().getPassword(user.getUsername());
        //判断密码
        try {
            oldPassword = EncrypMD5.eccrypt(oldPassword);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("修改失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.MODIFICATION_PASSWORD_FAILED, lang);
        }
        if (!oldPassword.equals(rpassword)) {
//            return AjaxResult.errorResult("原密码不正确，请输入重新输入");
            return MultilingualResult.errorResultV2(PROMPTS.ORIGINAL_PASSWORD_ERROR, lang);
        }

        // 密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("修改失败，请稍后再试2");
            return MultilingualResult.errorResultV2(PROMPTS.PASSWORD_ENCRYPTION_FAILED, lang);
        }

        //修改密码
        if (!User.modifyUserPassword(user.getUsername(), password)) {
//            AjaxResult.errorResult("修改密码失败，请稍后再试");
            MultilingualResult.errorResultV2(PROMPTS.MODIFICATION_PASSWORD_FAILED, lang);
        }
        UserPwdMemory.getInstance().modifyPassword(user.getUsername(), password);

        //同步修改密码
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_PASSWORD_MODIFY).setStr01(user.getUsername()).setStr02(password);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);

        return AjaxResult.successResult();
    }


    //修改用户类型
    @RequestMapping(method = RequestMethod.POST, value = "/superAdmin/userType/modify")
    @ResponseBody
    public String modifyUserType(String token, String username, Integer userType, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        int amdinType = user.getUserType();
        if (0 == amdinType - UserType.USER) {
//            return AjaxResult.errorResult("您没有登录管理后台的权限，请联系客服");
            return MultilingualResult.errorResultV2(PROMPTS.NO_ADMINISTRATIVE, lang);
        }

        if (null == userType || userType <= 0) {
//            return AjaxResult.errorResult("请选择用户类型");
            return MultilingualResult.errorResultV2(PROMPTS.SELECT_USER_TYPE, lang);
        }
        //修改用户类型
//        UserInfoMemory.getInstance().modifyUserType(username, userType);

//        user.getInstance().modifyUserType(username, userType);
        //同步修改用户类型
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_TYPE_MODIFY).setStr01(username).setInt01(userType);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);

        return AjaxResult.successResult();
    }


    //用户获取个人信息
    @RequestMapping(method = RequestMethod.POST, value = "/user/info/get")
    @ResponseBody
    public String getUserInfo(String token, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        UserInfo info = UserInfoMemory.getInstance().getUserInfo(user.getUsername());
        if (null == info) {
//            return AjaxResult.errorResult("当前用户信息不存在请查证");
            return MultilingualResult.errorResultV2(PROMPTS.USER_INFORMATION_NOT_EXIST, lang);
        }

        UserInfoVO infoVO = new UserInfoVO();
        try {
            ObjectUtils.copyPropertiesExclude(info, infoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("获取失败，请稍后重试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
        }

        if (null != infoVO) {
            if (ValidateUtil.isNotNull(infoVO.getSignPhoto()) && ValidateUtil.isNotNetUrl(infoVO.getSignPhoto())) {
//                infoVO.setSignPhoto(Common.imageUrl + infoVO.getSignPhoto());
                infoVO.setSignPhoto(SYS_CONFIG_PATH.IMAGE_BASE_URL + infoVO.getSignPhoto());
            }
        }

        List<UserAddress> userAddressList = UserAddressMemory.getInstance().listOfUser(user.getUsername());
        if (ValidateUtil.isAbsList(userAddressList)) {
            List<UserAddressVO> voList = new ArrayList<UserAddressVO>();
            for (int i = 0; i < userAddressList.size(); i++) {
                if (null == userAddressList.get(i)) {
                    continue;
                }
                UserAddressVO userAddressVO = new UserAddressVO();
                try {
                    ObjectUtils.copyPropertiesExclude(userAddressList.get(i), userAddressVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null != userAddressVO) {
                    voList.add(userAddressVO);
                }
            }
            if (ValidateUtil.isAbsList(voList)) {
                infoVO.setUserAddress(voList);
            }
        }

        switch (info.getUserType()) {
            case UserType.SHOP_OWNER: {//店主
                //获取店铺信息
//                List<ShopInfo> list = ShopMemory.getInstance().getShopListByUserName(info.getUsername());
//                List<ShopInfoVO> voList = new ArrayList<>();
//                for (int i = 0; i < list.size(); i++) {
//                    ShopInfoVO infoVO1 = new ShopInfoVO();
//                    try {
//                        ObjectUtils.copyPropertiesExclude(list.get(i), infoVO1, null);
//                    } catch (Exception e) {
//                        e.printStackTrace();
////                        return AjaxResult.errorResult("登录失败，请稍后再试.");
//                        return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
//                    }
//                    voList.add(infoVO1);
//                }
//                if (null != list && list.size() > 0) {
//                    infoVO.setShop(voList);
//                }
            }
            break;
            case UserType.USER: {//用户
            }
            break;
            case UserType.POSTMAN: {
                //如果是配送员的话返回配送员的信息
                if (0 == UserType.POSTMAN - infoVO.getUserType()) {
                    CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(user.getUsername());
                    if (null != cityPostman) {
                        CityPostmanVO postmanVO = PostmanMan.getOne(cityPostman);
                        infoVO.setPostmanInfo(postmanVO);
                    }
                }
            }
            break;
        }

        // 多维数据权限可能会不准确 所以不管用户的权限是多少  直接去拿用户的商户信息
        List<ShopInfo> list = ShopMemory.getInstance().getShopListByUserName(info.getUsername());
        if (list != null && !list.isEmpty()) {
            List<ShopInfoVO> voList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                ShopInfoVO infoVO1 = new ShopInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), infoVO1, null);
                } catch (Exception e) {
                    e.printStackTrace();
//                        return AjaxResult.errorResult("登录失败，请稍后再试.");
                    return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
                }
                voList.add(infoVO1);
            }
            if (null != voList && voList.size() > 0) {
                infoVO.setShop(voList);
            }
        }

//        UserWallet userWallet = UserWalletMemory.getInstance().getWallet(user.getUsername());
//        if (null != userWallet) {
//            UserWallet walletVO = new UserWallet();
//            try {
//                ObjectUtils.copyPropertiesExclude(userWallet, walletVO, null);
//            } catch (Exception e) {
//                e.printStackTrace();
//                walletVO = null;
//            }
//            if (null != walletVO) {
//                Double totalMoney = 0d;
//                Double awardMoney = userWallet.getAwardMoney();
//                Double money = userWallet.getMoney();
//                if (ValidateUtil.isNotAbsDouble(money)) {
//                    money = 0d;
//                }
//                if (ValidateUtil.isNotAbsDouble(awardMoney)) {
//                    awardMoney = 0d;
//                }
//                totalMoney = JYMathDoubleUtils.add(money, awardMoney);
//                walletVO.setMoney(totalMoney);
//                infoVO.setUserWallet(walletVO);
//            }
//        }

        UserWallet userWallet = WalletAction.getWallet(user.getUsername());
        if (null != userWallet) {
            infoVO.setUserWallet(userWallet);
        }

        return AjaxResult.successResult(infoVO);
    }

    //用户获取个人信息
    @RequestMapping(method = RequestMethod.POST, value = "/admin/get/user/info")
    @ResponseBody
    public String getUserInfo(String token, String username, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (StringUtils.isBlank(username)) {
            return AjaxResult.errorResult("信息不能为空");
        }
        UserInfo info = UserInfoMemory.getInstance().getUserInfo(username);
        if (null == info) {
            return MultilingualResult.errorResultV2(PROMPTS.USER_INFORMATION_NOT_EXIST, lang);
        }
        UserInfoVO infoVO = new UserInfoVO();
        try {
            ObjectUtils.copyPropertiesExclude(info, infoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_GET_USER_INFORMATION, lang);
        }
        return AjaxResult.successResult(infoVO);
    }

    //修改个人信息
    @RequestMapping(method = RequestMethod.POST, value = "/user/info/modify")
    @ResponseBody
    public String modifyUserInfo(String token, UserInfoVO info, String lang, FileUploadInfo fileUploadInfo) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (null == info) {
//            return AjaxResult.errorResult("请补全信息后再试");
            return MultilingualResult.errorResultV2(PROMPTS.COMPLETE_INFORMATION, lang);
        }

        //fileUploadInfo 用到image
        StringBuilder imgBuilder = new StringBuilder();
//         if (null != fileUploadInfo && null != fileUploadInfo.getImage()) {
//             //存储图片
// //            String filePath = JYImageUtils.saveImage(Common.USERIMAGE, fileUploadInfo.getImage());
//             String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.USER_IMAGE, fileUploadInfo.getImage());
//             if (null == filePath) {
// //                return AjaxResult.errorResult("存储图片失败，请稍后再试");
//                 return MultilingualResult.errorResultV2(PROMPTS.FAILED_SAVE_IMG, lang);
//             }
//             info.setSignPhoto(filePath);
//             imgBuilder.append(" ,signPhoto='").append(filePath).append("' ");
//         }


        if (null != fileUploadInfo) {
            if (null != fileUploadInfo.getImage()) {
                //存储图片
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.USER_IMAGE, fileUploadInfo.getImage());
                if (null == filePath) {
                    return MultilingualResult.errorResultV2(PROMPTS.FAILED_SAVE_IMG, lang);
                }
                info.setSignPhoto(filePath);
                imgBuilder.append(" ,signPhoto='").append(filePath).append("' ");
            } else if (null != fileUploadInfo.getBase64Img()) {
                //存储图片
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.USER_IMAGE, fileUploadInfo.getBase64Img());
                if (null == filePath) {
                    return MultilingualResult.errorResultV2(PROMPTS.FAILED_SAVE_IMG, lang);
                }
                info.setSignPhoto(filePath);
                imgBuilder.append(" ,signPhoto='").append(filePath).append("' ");
            }
        }

        String city = info.getCity();
//        if (null != SYS_SETTINGS.HAS_MULTILINGUAL && 0 == 1 - SYS_SETTINGS.HAS_MULTILINGUAL) {//多语言版
//            if (ValidateUtil.isNotNull(city)) {
//                city = JYPinyinHelper.isChinese(city) ? JYPinyinHelper.toHanyuPinyin(city) : city.toLowerCase();
//            }
//        }

        StringBuilder sb = new StringBuilder();
        sb.append("update ").append(PojoTables.UserInfo).append(" set name='").append(info.getName())
                .append("',signature='").append(info.getSignature()).append("',telPhone='").append(info.getTelPhone())
                .append("',phone2='").append(info.getPhone2()).append("',sex='").append(info.getSex())
                .append("',updateUser='").append(user.getUsername()).append("',province='").append(info.getProvince())
                .append("',city='").append(city).append("',county='").append(info.getCounty()).append("',address='").append(info.getAddress())
                .append("' ").append(imgBuilder.toString()).append(" where delFlag = 0 and username = '").append(user.getUsername()).append("'");

        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("修改个人信息失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.MODIFY_PERSON_INFO_ERROR, lang);
        }

        UserInfoMemory.getInstance().modifyUserInfo(user.getUsername());
        // 修改商户信息
        UserInfo info1 = UserInfoMemory.getInstance().getUserInfo(user.getUsername());
        modifyUserShop(info1);
        //同步修改用户信息
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_INFO_MODIFY).setStr01(user.getUsername());//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);


        //分销同步用户信息
        UserDistributeInfoSyncUtils.syncByUsername(user.getUsername());

        return AjaxResult.successResult();
    }

    private static void modifyUserShop(UserInfo user) {
        if (user == null) {
            return;
        }
        ShopInfo shop = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (shop == null) {
            return;
        }
        StringBuffer sql = new StringBuffer();
        sql.append("update ").append(PojoTables.ShopInfo)
                .append(" set ownName ='").append(user.getName()).append("'")
                .append(" where id = ").append(shop.getId());
        try {
            UserDaoSql.getInstance().executeBySql(sql.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        ShopMemory.getInstance().modifyById(shop.getId());
        try {
            JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.SHOP_INFO_UPDATE).setLong01(shop.getId());
            JmsSender.setTopicSender(notify);
        } catch (Exception e) {
        }
    }

    //  重置密码
    @RequestMapping(method = RequestMethod.POST, value = "/admin/user/reset/password")
    @ResponseBody
    public String admin_user_password_reset(String username, String lang) {
        if (StringUtils.isEmpty(username)) {
            return AjaxResult.errorResult("重置账号不能为空");
        }
        String password = "123456";
        // 密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.PASSWORD_ENCRYPTION_FAILED, lang);
        }

        if (!User.modifyUserPassword(username, password)) {
            return MultilingualResult.errorResultV2(PROMPTS.MODIFICATION_PASSWORD_FAILED, lang);
        }
        UserPwdMemory.getInstance().modifyPassword(username, password);
        //同步修改密码
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_PASSWORD_MODIFY).setStr01(username).setStr02(password);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);

        return AjaxResult.successResult();
    }


    //-----------------------个人信息认证
    //用户提交个人信息认证
    @RequestMapping(method = RequestMethod.POST, value = "/user/info/verify")
    @ResponseBody
    public String userInfoVerify(String token, InfoVerify info, String lang, FileUploadInfo fileUploadInfo) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (null == info) {
//            return AjaxResult.errorResult("请补全信息后再试");
            return MultilingualResult.errorResultV2(PROMPTS.COMPLETE_INFORMATION, lang);
        }
        info.setUserType(user.getUserType());


        return AjaxResult.successResult();
    }

    //-----------------------员工申请公司（小志）
    //用户注册V2
    @RequestMapping(method = RequestMethod.POST, value = "/user/register/byTelCode/V2")
    @ResponseBody
    public String user_registerV2(String username, String telCode, String password, String lang, String devJson) {

        ResultInfo resultInfo = UserLogin.registerByTelCode(username, true, password, telCode, false, null, devJson);//单独注册接口
        if (null == resultInfo) {
//            return AjaxResult.errorResult("注册失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.FAILED_REGISTER_USER, lang);
        }
        if (null != resultInfo && !resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }
        return AjaxResult.successResult();

    }


    //员工申请公司的列表
    @RequestMapping(method = RequestMethod.POST, value = "/user/company/verify/list")
    @ResponseBody
    public String companyVerifyList(String token, Integer isVerify, String companyId) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (null == isVerify) {
            isVerify = 10;
        }

        QueryCondition query = QueryCondition.getInstance();
        Expression expression = Expression.getInstance();
        expression.addChild("delFlag", 0);
        expression.addChild("isVerify", isVerify);
        if (ValidateUtil.isNotNull(companyId)) {
            expression.addChild("companyId", companyId);
        }
        query.addCondition(expression);
        String sql = DaoUtils.getSql(PojoTables.USER_INFO_EXTRA, query);
        List<UserInfoExtra> list = null;
        try {
            list = (List<UserInfoExtra>) UserDaoSql.getInstance().list(UserInfoExtra.class, sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        if (ValidateUtil.isAbsList(list)) {
            return AjaxResult.successResult(list.size(), list);
        }
        return AjaxResult.successResult(0, null);
    }

    //用户申请公司审核通过/拒绝
    @RequestMapping(method = RequestMethod.POST, value = "/user/company/verify/pass")
    @ResponseBody
    public String companyVerifypass(String token, String username, String companyId, Integer isVerify, String reason) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(username)) {
            return AjaxResult.errorResult("审核的账号不能为空！");
        }
        if (null == isVerify) {
            return AjaxResult.errorResult("审核状态不能为空！");
        }

        // 改变申请公司的状态
        StringBuffer sb = new StringBuffer();
        sb.append("update ").append(PojoTables.USER_INFO_EXTRA).append(" set isVerify =").append(isVerify)
                .append(", verifyTime = ").append(System.currentTimeMillis())
                .append(StringUtils.isNotEmpty(reason) ? ", extra2='" + reason + "'" : "")
                .append(",updateUser='").append(user.getUsername())
                .append("' where delFlag = 0 and username = ").append(username);
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
        }

        UserInfoExtraMemory.getInstance().addOrModify(username);


        return AjaxResult.successResult();
    }

    // 获取用户的权限
    @RequestMapping(method = RequestMethod.POST, value = "/user/power/info")
    @ResponseBody
    public String getPowerInfo(String token, String username) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(username)) {
            return AjaxResult.errorResult("用户名不能为空!");
        }

        UserInfoExtra userInfoExtra = UserInfoExtraMemory.getInstance().getByUsername(username);
        if (null == userInfoExtra) {
            return AjaxResult.errorResult("未查询到信息");
        }
        return AjaxResult.successResult(userInfoExtra);
    }

    //获取所有用户额外信息
    @RequestMapping(method = RequestMethod.POST, value = "/user/extra/list")
    @ResponseBody
    public String getUserExtraList(String token) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        List<UserInfoExtra> list = UserInfoExtraMemory.getInstance().listOfAll();
        if (ValidateUtil.isAbsList(list)) {
            List<UserInfoExtra> volist = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                if (ValidateUtil.isNotNull(list.get(i).getVisitPower())) {
                    UserInfoExtra userInfoE = new UserInfoExtra();
                    userInfoE.setUsername(list.get(i).getUsername());
                    userInfoE.setVisitPower(list.get(i).getVisitPower());
                    volist.add(userInfoE);
                }
            }
            return AjaxResult.successResult(volist.size(), volist);
        }
        return AjaxResult.successResult(0, null);
    }


    // 修改代理的登录的密码
    @RequestMapping(method = RequestMethod.POST, value = "admin/modify/login/passwd")
    @ResponseBody
    public String modifySysAdmin(String token, String username, Long cityAdminId, String password) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (StringUtils.isEmpty(password)) {
            return AjaxResult.errorResult("密码不能为空");
        }
        SysCityAdmin cityAdmin = null;

        if (cityAdmin == null) {
            return AjaxResult.errorResult("未获取到代理信息");
        }
        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(cityAdmin.getUsername());
        if (userInfo == null) {
            return AjaxResult.errorResult("未获取到用户信息");
        }
        // 密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("转化密码错误，请稍后再试");
        }

        boolean b = User.modifyUserPassword(userInfo.getUsername(), password);
        if (!b) {
            return AjaxResult.errorResult("修改登录密码失败");
        }
        UserPwdMemory.getInstance().modifyPassword(userInfo.getUsername(), password);
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_PASSWORD_MODIFY).setStr01(userInfo.getUsername()).setStr02(password);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);
        return AjaxResult.successResult();
    }


    // 修改支付密码通过手机号
    @RequestMapping(method = RequestMethod.POST, value = "/user/pay/password/getTelCode")
    @ResponseBody
    public String get_telCode_because_payPassword(HttpServletRequest request, String sysAppKey, String token,
                                                  String areaCode,// 手机区号
                                                  String username) {
        // 用户
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (null == username || username.equals("")) {
            return AjaxResult.errorResult("请输入手机号");
        }
        String telUsername = "";
        // 目前只能使用注册的手机号验证
        if (User.isPhoneLogin()) {
            if (StringUtils.isEmpty(user.getPhone())) {
                // if (!user.getPhone().equals(username)) {
                //     return AjaxResult.errorResult("请输入注册时的手机号或联系客服");
                // }
                // telUsername = username;
            } else {
                // if (!user.getUsername().equals(username)) {
                //     return AjaxResult.errorResult("请输入注册时的手机号或联系客服");
                // }
            }
            // telUsername = username;
        } else {
            // if (!user.getUsername().equals(username)) {
            //     return AjaxResult.errorResult("请输入注册时的手机号或联系客服");
            // }
            // telUsername = user.getUsername();
        }
        telUsername = user.getUsername();

        // 将注册用户的验证码存储在mongoDB
        String code = ToolUtils.getTelCode(); // 6位随机码
        BasicDBObject document = new BasicDBObject();
        // document.put("username", username);
        document.put("username", telUsername);

        DBObject value1 = new BasicDBObject();
        value1.put("telCode", code);
        value1.put("createTim", SysSetting.getCurDate());
        DBObject upValue = new BasicDBObject();
        upValue.put("$push", value1); // 数组的形式

        boolean flag = MongoDaoImpl.getInstance().update(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSPayPasswdCol, document, upValue, true);
        if (flag == true) {
            JYSmsSeverBusiness.sendSMS(sysAppKey, areaCode, username, SMS_TYPE.MODIFY_PAY_PASSWORD, code, RightFilter.getIpAddr(request));
            StringBuffer buffer = new StringBuffer("{\"status\":1,\"isShow\":").append(0).append(",\"telCode\":\"").append("").append("\"}");
            System.out.println(code);
            return buffer.toString();
        } else {
            return AjaxResult.errorResult("获取失败，请稍后再试");
        }
    }

    // mod
    @RequestMapping(method = RequestMethod.POST, value = "/user/pay/modify/byTelCode")
    @ResponseBody
    public String updatePayPasswordByTelCode(String token, String telCode, String payPassword) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (ValidateUtil.isNull(telCode)) {
            return AjaxResult.errorResult("修改密码失败，验证码不能为空");
        }

        if (ValidateUtil.isNull(payPassword)) {
            return AjaxResult.errorResult("支付密码不能为空");
        }
        String username = "";
        if (User.isPhoneLogin()) {
            username = StringUtils.isNotEmpty(user.getPhone()) ? user.getPhone() : user.getUsername();
        } else {
            username = user.getUsername();
        }

        // 验证码
        HashMap<String, Object> map = new HashMap<String, Object>();
//        map.put("username", user.getUsername());
        map.put("username", user.getUsername());
        List<HashMap<String, Object>> list = MongoDaoImpl.getInstance()
                .find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSPayPasswdCol, map, 1);
        if (list == null || list.size() < 1) {
            return AjaxResult.errorResult("请获取验证码");
        }
        // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
        if (list.get(0).get("telCode") == null
                || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
            return AjaxResult.errorResult("请输入正确的验证码！");
        }
        try {
            payPassword = EncrypMD5.eccrypt(payPassword);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("转化密码错误，请稍后再试");
        }
        if (!modifyPayPassword(user.getUsername(), payPassword)) {
            return AjaxResult.errorResult("修改支付密码失败，请稍后重试");
        }
        UserPwdMemory.getInstance().modifyPayPassword(user.getUsername(), payPassword);
        //同步修改支付密码
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_PAY_PASSWORD_MODIFY).setStr01(user.getUsername()).setStr02(payPassword);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);
        return AjaxResult.successResult();
    }


    @RequestMapping(method = RequestMethod.POST, value = "/user/pay/password/modify")
    @ResponseBody
    public String updatePayPassword(String token, String oldPayPassword, String newPayPassword) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (newPayPassword == null || "".equals(newPayPassword)) {
            return AjaxResult.errorResult("请输入新支付密码");
        }
        String getPayPassword = UserPwdMemory.getInstance().getPayPassword(user.getUsername());
        // 若是支付密码没有设置，则设置newpayPassword 为支付密码
        if (getPayPassword == null || "".equals(getPayPassword)) {
            // bu check 原密码；
        } else {
            if (oldPayPassword == null || "".equals(oldPayPassword)) {
                return AjaxResult.errorResult("请输入原密码");
            }
            try {
                oldPayPassword = EncrypMD5.eccrypt(oldPayPassword);
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.errorResult("修改支付密码失败，请联系管理员");
            }
            if (!getPayPassword.equals(oldPayPassword)) {
                return AjaxResult.errorResult("原密码不正确");
            }
        }

        // 加密
        try {
            newPayPassword = EncrypMD5.eccrypt(newPayPassword);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("修改支付密码失败");
        }
        if (!modifyPayPassword(user.getUsername(), newPayPassword)) {
            return AjaxResult.errorResult("修改支付密码失败,请稍后重试");
        }
        UserPwdMemory.getInstance().modifyPayPassword(user.getUsername(), newPayPassword);
        //同步修改支付密码
        JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_PAY_PASSWORD_MODIFY).setStr01(user.getUsername()).setStr02(newPayPassword);//o2o.business.jms  MQDataBusiness
        JmsSender.setTopicSender(notify);
        return AjaxResult.successResult();
    }

    // 修改支付密码
    private boolean modifyPayPassword(String username, String payPassword) {
        String sql = "update " + PojoTables.UserPasswordInfo + " set payPassword = '" + payPassword + "' where username = '" + username + "' and delFlag = 0";
        try {
            UserDaoSql.getInstance().executeBySql(sql);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    // 团购商家相关功能
    // 团购商家登录
    @RequestMapping(method = RequestMethod.POST, value = "/group/shop/login/byPassword")
    @ResponseBody
    public String group_shop_login_byPassword(String username, String password, String lang) {
        ResultInfo resultInfo = loginV2(username, password, UserType.SHOP_OWNER, null);
        if (!resultInfo.isSuccess()) {
            return MultilingualResult.errorResultV2(resultInfo.getError(), lang);
        }
        UserInfoVO userInfoVO = (UserInfoVO) resultInfo.getObj();
        UserInfoShoperVO infoVO = new UserInfoShoperVO();
        try {
            ObjectUtils.copyPropertiesExclude(userInfoVO, infoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
        }
        ShopMemory.getInstance().getShopByUsername(userInfoVO.getUsername());
        List<ShopInfo> list = ShopMemory.getInstance().getShopListByUserName(userInfoVO.getUsername());
        if (ValidateUtil.isAbsList(list)) {
            List<ShopInfoVO> voList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                // 是不是团购商家
                if (!ShopCategoryMan.validGroupShopType(list.get(i).getShopCategory())) {
                    return AjaxResult.errorResult("您不是团购商家");
                }
                //0 锁定  1正常
                if (0 == list.get(i).getIsLock()) {
                    return MultilingualResult.errorResultV2(PROMPTS.STORE_IS_LOCKED, lang);
                }
                ShopInfoVO infoVO1 = new ShopInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), infoVO1, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    return MultilingualResult.errorResultV2(PROMPTS.LOGIN_ERROR, lang);
                }

                voList.add(infoVO1);
            }
            if (null != list && list.size() > 0) {
                infoVO.setShop(voList);
            }
        }
        CityAgent cityAgent = CityAgentMemory.getInstance().getByUsername(infoVO.getUsername());
        if (null != cityAgent) {
            CityAgentVO cityAgentVO = new CityAgentVO();
            try {
                ObjectUtils.copyPropertiesExclude(cityAgent, cityAgentVO, null);
            } catch (Exception e) {
                e.printStackTrace();
                cityAgentVO = null;
            }
            if (null != cityAgentVO) {
                infoVO.setAgent(cityAgentVO);
            }
        }
        return AjaxResult.successResult(infoVO);
    }


    // 超级管理员修改用户的用户的账号信息
    @RequestMapping(method = RequestMethod.POST, value = "/admin/modify/user/login/phone")
    @ResponseBody
    public String modify_user_login_phone(String token, String sysAppKey, String username, String phone) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (!User.hasSuperAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您没有操作权限");
        }
        if (!User.isPhoneLogin()) {
            return AjaxResult.errorResult("当前系统尚不支持修改");
        }
        if (StringUtils.isBlank(username)) {
            return AjaxResult.errorResult("用户标识不能为空");
        }
        try {
            User.modifyUserLoginPhone(user, username, phone);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult(e.getMessage());
        }
        return AjaxResult.successResult();
    }

    // 超级管理员修改用户的用户的账号信息
    @RequestMapping(method = RequestMethod.POST, value = "/admin/modify/shop/login/phone")
    @ResponseBody
    public String modify_shop_login_phone(String token, String sysAppKey, Long shopId, String phone) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (User.hasSuperAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您没有操作权限");
        }
        if (!User.isPhoneLogin()) {
            return AjaxResult.errorResult("当前系统尚不支持修改");
        }
        if (ValidateUtil.isNotID(shopId)) {
            return AjaxResult.errorResult("店铺id不能为空");
        }
        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(shopId);
        if (shopInfo == null) {
            return AjaxResult.errorResult("未获取到店铺信息");
        }
        try {
            User.modifyUserLoginPhone(user, shopInfo.getOwnUsername(), phone);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult(e.getMessage());
        }
        return AjaxResult.successResult();
    }

    // 认证设置为企业或者普通用户
    @RequestMapping(method = RequestMethod.POST, value = "/user/company/state/set")
    @ResponseBody
    public String user_company_state_set(String token, Integer state, String companyName, String companyAddress,
                                         FileUploadInfo fileUploadInfo) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (state == null) {
            state = 1;
        }
        if (Optional.ofNullable(user.getCompanyUserState()).orElse(0) - USER_COMPANY_STATE.STATE_NO_SELECT != 0) {
            return AjaxResult.errorResult("当前状态下不可操作");
        }
        if (state == USER_COMPANY_STATE.STATE_ORDINARY) {
            StringBuffer sql = new StringBuffer();
            sql.append(" update ").append(PojoTables.UserInfo)
                    .append(" set updateUser ='").append(user.getUsername()).append("'")
                    .append(", companyUserState = ").append(state)
                    .append(" where delFlag = 0 and username ='").append(user.getUsername()).append("' ");
            try {
                UserDaoSql.getInstance().executeBySql(sql.toString());
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.errorResult(e.getMessage());
            }
            UserInfoMemory.getInstance().modifyUserInfo(user.getUsername());
        } else if (state == USER_COMPANY_STATE.STATE_COMPANY_VERIFY) {
            String companyBuzzLicUrl = "";
            if (null != fileUploadInfo && (null != fileUploadInfo.getImage() || StringUtils.isNotEmpty(fileUploadInfo.getBase64Img()))) {
                String filePath = StringUtils.isNotEmpty(fileUploadInfo.getBase64Img()) ? JYImageUtils.saveImage
                        (SYS_CONFIG_PATH.USER_IMAGE, fileUploadInfo.getBase64Img()) : JYImageUtils.saveImage(SYS_CONFIG_PATH
                        .SHOP_IMAGE, fileUploadInfo.getImage());
                if (null == filePath) {
                    return AjaxResult.errorResult("存图片失败");
                }
                companyBuzzLicUrl = filePath;
            }
            Connection con = null;
            try {
                con = UserDaoSql.getInstance().getConnection(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            StringBuffer sql = new StringBuffer();
            sql.append(" update ").append(PojoTables.UserInfo)
                    .append(" set updateUser ='").append(user.getUsername()).append("'")
                    .append(", companyUserState = ").append(state)
                    .append(" where delFlag = 0 and username ='").append(user.getUsername()).append("' ");

            UserInfoExtra infoExtra = UserInfoExtraMemory.getInstance().getByUsername(user.getUsername());
            if (infoExtra != null) {
                StringBuffer sqlExtra = new StringBuffer();
                sqlExtra.append(" update ").append(PojoTables.USER_INFO_EXTRA)
                        .append(" set updateUser ='").append(user.getUsername()).append("' ");

                if (ValidateUtil.isNotNull(companyAddress)) {
                    sqlExtra.append(", companyAddress = '").append(companyAddress).append("' ");
                }
                if (ValidateUtil.isNotNull(companyName)) {
                    sqlExtra.append(", companyName = '").append(companyName).append("' ");
                }
                if (ValidateUtil.isNotNull(companyBuzzLicUrl)) {
                    sqlExtra.append(", companyBuzzLicUrl = '").append(companyBuzzLicUrl).append("' ");
                }
                sqlExtra.append(" where delFlag = 0 and username = '").append(infoExtra.getUsername()).append("'");
                try {
                    UserDaoSql.getInstance().executeBySql(sql.toString(), con);
                    UserDaoSql.getInstance().executeBySql(sqlExtra.toString(), con);
                    con.commit();
                } catch (SQLException e) {
                    e.printStackTrace();
                    UserDaoSql.getInstance().rollback(con);
                    return AjaxResult.errorResult(e.getMessage());
                } finally {
                    UserDaoSql.getInstance().close(con);
                }
            } else {
                //没有  新增
                UserInfoExtra userInfoExtra = new UserInfoExtra();
                userInfoExtra.setUsername(user.getUsername());
                userInfoExtra.setDelFlag(0);
                userInfoExtra.setCreateTime(DateUtils.getCurrTime());
                userInfoExtra.setCreateUser(user.getUsername());
                userInfoExtra.setCompanyAddress(companyAddress);
                userInfoExtra.setCompanyName(companyName);
                userInfoExtra.setCompanyBuzzLicUrl(companyBuzzLicUrl);
                try {
                    UserDaoSql.getInstance().saveObj(PojoTables.USER_INFO_EXTRA, userInfoExtra, con);
                    UserDaoSql.getInstance().executeBySql(sql.toString(), con);
                    con.commit();
                } catch (SQLException e) {
                    e.printStackTrace();
                    UserDaoSql.getInstance().rollback(con);
                    return AjaxResult.errorResult(e.getMessage());
                } finally {
                    UserDaoSql.getInstance().close(con);
                }
            }
            UserInfoMemory.getInstance().modifyUserInfo(user.getUsername());
            UserInfoExtraMemory.getInstance().addOrModify(user.getUsername());
        } else {
            return AjaxResult.errorResult("操作状态不正确");
        }
        return AjaxResult.successResult();
    }

    // 定时任务
    //秒  分  时  日  月  星期几  年
    @Scheduled(cron = "0 10 0 * * *")
    public void task01() {
        requestMap.clear();
    }
}

